﻿app.controller("cursoController", function ($scope, cursoService) {
    $scope.hola = function () {
        console.log($scope.name);
    }

    list = function () {
        cursoService.getListByFilter().then(function (r) {
            $scope.cursos = r.data;
        }, function (err) {
            console.log("Errrrr:" + err.data);
        });
    };
    list();

    //otro metodo
    $scope.save = function () {
        if ($scope.curso.CursoId) {
            cursoService.update({ CursoId: "" }, $scope.curso).then(function (r) {
                console.log(r.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        } else {
            cursoService.create($scope.curso).then(function (resurlts) {
                console.log(resrults.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }



    $scope.delete = function (CursoId) {
        cursoService.delete({ "CursoId": CursoId }).then(function (r) {
            console.log("rd=" + r.data);
            list();
        }, function (err) {
            console.log("Errrrr:" + err.data);
        });
    }
    $scope.selec = function (c) {
        $scope.curso = c;
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }

    $scope.formVisibility = false;
    $scope.ShowForm = function () {
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }
    $scope.cancel = function () {
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }
});
/*
'use strict';
app.controller('cursoController', ['$scope', 'cursoService', function ($scope, cursoService) {

    $scope.list = [];

    cursoService.getList().then(function (results) {

        $scope.list = results.data;

    }, function (error) {
        //alert(error.data.message);
    });

}]);*/